﻿using MODEL;
using SysHelper;
using System;
using System.Collections.Generic;
using System.Data.Objects;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace SysController
{
    public static partial class SystemController
    {
        static SelectListItem selectItem = new SelectListItem() { Text = "请选择", Value = "-1", Selected = true };

        #region static List<SelectListItem> LanguageTypeList
        private static List<SelectListItem> _LanguageTypeList;

        public static List<SelectListItem> LanguageTypeList
        {
            get
            {
                if (_LanguageTypeList == null)
                {
                    _LanguageTypeList = OperateContext.CurrentContext.BllSession.ILanguageType_BLL.GetListByWhere(s => s.IsDel == false)
                        .Select(s => new SelectListItem() { Text = s.LanguageName, Value = s.LanguageTypeID.ToString() }).ToList();
                    _LanguageTypeList.Add(selectItem);
                }
                return _LanguageTypeList;
            }

        }
        #endregion

        #region static List<SelectListItem> ContrabandList
        private static List<SelectListItem> _ContrabandList;

        public static List<SelectListItem> ContrabandList
        {
            get
            {
                if (_ContrabandList == null)
                {
                    _ContrabandList = OperateContext.CurrentContext.BllSession.IView_Contraband_BLL.GetListByWhere(s => s.IsDel == false)
                    .Select(s => new SelectListItem { Text = s.ContrabandName, Value = s.ContrabandID.ToString() }).ToList();
                }
                return _ContrabandList;
            }

        }
        #endregion

        #region 获取分类 +static List<SelectListItem> GetCategory(int pid = 0）
        /// <summary>
        /// 获取分类
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public static List<SelectListItem> GetCategory(int pid = 0)
        {
            return OperateContext.CurrentContext.BllSession.IView_Category_BLL.GetListByWhere(s => s.IsDel == false && s.PCategoryID == pid)
                  .Select(s => new SelectListItem { Text = s.CategoryName, Value = s.CategoryID.ToString() }).ToList();
        } 
        #endregion

        #region static List<SelectListItem> ProductTypeList
        private static List<SelectListItem> _ProductTypeList;

        public static List<SelectListItem> ProductTypeList
        {
            get
            {
                if (_ProductTypeList == null)
                {
                    _ProductTypeList = OperateContext.CurrentContext.BllSession.IProductType_BLL.GetListByWhere(s => s.IsDel == false)
                        .Select(s => new SelectListItem { Text = s.ProductTypeName, Value = s.ProductTypeID.ToString() }).ToList();
                    _ProductTypeList.Add(selectItem);
                }
                return _ProductTypeList;
            }
        } 
        #endregion

        #region static List<SelectListItem> ProductStatuList
        private static List<SelectListItem> _ProductStatuList;

        public static List<SelectListItem> ProductStatuList
        {
            get
            {
                if (_ProductStatuList == null)
                {
                    _ProductStatuList = OperateContext.CurrentContext.BllSession.IProductStatu_BLL.GetListByWhere(s => s.IsDel == false)
                        .Select(s => new SelectListItem { Text = s.ProductStatusName, Value = s.ProductStatusID.ToString() }).ToList();
                    _ProductStatuList.Add(selectItem);
                }
                return _ProductStatuList;
            }
        } 
        #endregion

        #region static List<SelectListItem> ProductSpecList
        private static List<SelectListItem> _ProductSpecList;

        public static List<SelectListItem> ProductSpecList
        {
            get
            {
                if (_ProductSpecList == null)
                {
                    _ProductSpecList = OperateContext.CurrentContext.BllSession.IProductSpec_BLL.GetListByWhere(s => s.IsDel == false)
                        .Select(s => new SelectListItem { Text = s.SpecName, Value = s.ProductSpecID.ToString() }).ToList();
                    _ProductSpecList.Add(selectItem);
                }
                return _ProductSpecList;
            }
        } 
        #endregion

        #region static List<SelectListItem> TransportTypeList
        private static List<SelectListItem> _TransportTypeList;

        public static List<SelectListItem> TransportTypeList
        {
            get
            {
                if (_TransportTypeList == null)
                {
                    _TransportTypeList = OperateContext.CurrentContext.BllSession.ITransportType_BLL.GetListByWhere(s => s.IsDel == false)
                        .Select(s => new SelectListItem { Text = s.TransportTypeName, Value = s.TransportTypeID.ToString() }).ToList();
                    _TransportTypeList.Add(selectItem);
                }
                return _TransportTypeList;
            }
        } 
        #endregion

        #region static List<SelectListItem> StockList
        private static List<SelectListItem> _StockList;

        public static List<SelectListItem> StockList
        {
            get
            {
                if (_StockList == null)
                {
                    _StockList = OperateContext.CurrentContext.BllSession.IStock_BLL.GetListByWhere(s => s.IsDel == false)
                        .Select(s => new SelectListItem { Text = s.StockName, Value = s.StockID.ToString() }).ToList();
                    _StockList.Add(selectItem);
                }
                return _StockList;
            }
        } 
        #endregion

        
    }

    public static partial class SystemController
    {
        #region + static int AddProduct(Product model)
        public static int AddProduct(Product model)
        {
            OperateContext.CurrentContext.BllSession.IProduct_BLL.ModifyIsNullADD(model, s => s.Code == model.Code, true);
            return OperateContext.CurrentContext.BllSession.SaveChanges(typeof(Product).Name);
        } 
        #endregion

        #region + static int AddProductCost(ProductCost model)
        public static int AddProductCost(ProductCost model)
        {
            OperateContext.CurrentContext.BllSession.IProductCost_BLL.ModifyIsNullADD(model, s => s.Code == model.Code, true);
            return OperateContext.CurrentContext.BllSession.SaveChanges(typeof(ProductCost).Name);
        } 
        #endregion

        #region + static int AddProductConfig(ProductConfig model)
        public static int AddProductConfig(ProductConfig model)
        {
            OperateContext.CurrentContext.BllSession.IProductConfig_BLL.ModifyIsNullADD(model, s => s.Code == model.Code, true);
            return OperateContext.CurrentContext.BllSession.SaveChanges(typeof(ProductConfig).Name);
        } 
        #endregion

        #region + static int AddProductCategory(ProductCategory model)
        public static int AddProductCategory(ProductCategory model)
        {
            OperateContext.CurrentContext.BllSession.IProductCategory_BLL.ModifyIsNullADD(model, s => s.Code == model.Code, true);
            return OperateContext.CurrentContext.BllSession.SaveChanges(typeof(ProductCategory).Name);
        } 
        #endregion

        #region + static int AddProductPackageInfo(ProductPackageInfo model)
        public static int AddProductPackageInfo(ProductPackageInfo model)
        {
            OperateContext.CurrentContext.BllSession.IProductPackageInfo_BLL.ModifyIsNullADD(model, s => s.Code == model.Code, true);
            return OperateContext.CurrentContext.BllSession.SaveChanges(typeof(ProductPackageInfo).Name);
        } 
        #endregion

        #region + static int AddProductPicture(ProductPicture model)
        public static int AddProductPicture(ProductPicture model)
        {
            OperateContext.CurrentContext.BllSession.IProductPicture_BLL.ModifyIsNullADD(model, s => s.Code == model.Code, true);
            return OperateContext.CurrentContext.BllSession.SaveChanges(typeof(ProductPicture).Name);
        } 
        #endregion

        #region + static int AddProductProperty(ProductProperty model)
        public static int AddProductProperty(ProductProperty model)
        {
            OperateContext.CurrentContext.BllSession.IProductProperty_BLL.ModifyIsNullADD(model, s => s.Code == model.Code, true);
            return OperateContext.CurrentContext.BllSession.SaveChanges(typeof(ProductProperty).Name);
        } 
        #endregion

        #region + static int AddProductTranslation(ProductTranslation model)
        public static int AddProductTranslation(ProductTranslation model)
        {
            OperateContext.CurrentContext.BllSession.IProductTranslation_BLL.ModifyIsNullADD(model, s => s.Code == model.Code, true);
            return OperateContext.CurrentContext.BllSession.SaveChanges(typeof(ProductTranslation).Name);
        } 
        #endregion
         
    }
}
